<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiImageImgtinyTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_image_imgtiny';

    /**
     * Run the migrations.
     * @table qii_image_imgtiny
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('attach_id')->comment('图片关联ID');
            $table->unsignedInteger('target_id')->default('0')->comment('对象id-外键');
            $table->char('target_type', 10)->default('')->comment('对象类型');
            $table->char('tag', 30)->default('')->comment('标记');
            $table->unsignedInteger('image_id')->default('0')->comment('图片的主键-外键关联image表');
            $table->unsignedInteger('last_modified')->default('0')->comment('更新时间');

            $table->index(["tag"], 'search');

            $table->index(["target_id", "target_type"], 'target');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
